package primary.others;

/**
 * @Author Elephas
 * @Date 2022/1/11
 **/
public class HammingWeight {
    public static void main(String[] args) {
        int x = hammingWeight(-1);
        return;
    }

    public static int hammingWeight(int n){
        int distance = 0;
        for (int i = 0; i < 32; i++) {
            distance += n&0x1;
            n = n>>1;
        }
        return distance;
    }

}
